/**
 * Created by Administrator on 2017/6/12.
 */
var mongoose = require('../db/db');
var MovieSchema = require('../schemas/movie');

MovieSchema.static('findById', function (id, callback) {
  return this.findOne({_id: id}).populate('categories').exec(callback);
});

MovieSchema.static('findAll', function (callback) {
  return this.find({}).sort({time: 1}).exec(callback);
});

MovieSchema.static('findByName', function (name, callback) {
  var name = new RegExp(name);
  return this.find({name: name}).sort({time: -1}).exec(callback);
});

module.exports = mongoose.model('Movie', MovieSchema);